package channels

import "fmt"

func ChannelBuffering() {
	messages := make(chan string, 2)
	messages <- "buffered"
	messages <- "channel"
	fmt.Println(<-messages)
	fmt.Println(<-messages)
}

func Directions() {
	pings := make(chan string, 1)
	pongs := make(chan string, 1)
	ping(pings, "passed message")
	pong(pings, pongs)
	fmt.Println(<-pongs)
}

func MakeChannel() {
	messages := make(chan string)
	messages2 := make(chan string)

	go func() { messages <- "ping" }()
	go func() {
		msg1 := <-messages
		messages2 <- msg1 + " hahah"
	}()
	msg := <-messages2
	fmt.Println(msg)
}

func ping(pings chan<- string, msg string) {
	pings <- msg
}

func pong(pings <-chan string, pongs chan<- string) {
	msg := <-pings
	pongs <- msg
}
